package TemplateMethodCode;

public abstract class AbstractAccount {
    protected double money;
    protected double year;

    public AbstractAccount(double money, double year) {
        this.money = money;
        this.year = year;
    }

    public void calculateInterest() {
        fetchUserInfo();
        String accountType = getAccountType();
        double interest = computeInterest();
        displayInterest(accountType, interest);
    }

    // 查询用户信息
    private void fetchUserInfo() {
        System.out.println("查询用户信息：");
        System.out.printf("用户存款：%.2f元 | 存款时长: %.0f年\n",money,year);
    }

    // 显示利息
    private void displayInterest(String accountType, double interest) {
        System.out.printf("账户类型: %s | 预计利息: %.2f元\n", accountType, interest);
    }

    // 获取账户类型
    protected abstract String getAccountType();

    // 计算利息
    protected abstract double computeInterest();
}

